-
Notifications
You must be signed in to change notification settings - Fork 4.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ConfigureHostOptions implemetation #49502
Conversation
Note regarding the This serves as a reminder for when your PR is modifying a ref *.cs file and adding/modifying public APIs, to please make sure the API implementation in the src *.cs file is documented with triple slash comments, so the PR reviewers can sign off that change. |
Tagging subscribers to this area: @eerhardt, @maryamariyan Issue Details
|
src/libraries/Microsoft.Extensions.Hosting/src/HostingHostBuilderExtensions.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR @I-SER-I , could you please add tests for the new API under src/libraries/Microsoft.Extensions.Hosting/tests/UnitTests/HostBuilderTests.cs
?
src/libraries/Microsoft.Extensions.Hosting/ref/Microsoft.Extensions.Hosting.cs
Show resolved
Hide resolved
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns> | ||
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureDelegate) | ||
{ | ||
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: you could be using the other overload here for simplicity, since no context is passed around
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate)); | |
return hostBuilder.ConfigureServices(collection => collection.Configure(configureDelegate)); |
@@ -42,6 +42,7 @@ public static partial class HostingHostBuilderExtensions | |||
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostBuilderContext, Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; } | |||
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; } | |||
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureServices(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.DependencyInjection.IServiceCollection> configureDelegate) { throw null; } | |||
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostOptions> configureDelegate) { throw null; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Similar to how we have two ConfigureLogging overloads:
runtime/src/libraries/Microsoft.Extensions.Hosting/ref/Microsoft.Extensions.Hosting.cs
Lines 42 to 43 in 689c492
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostBuilderContext, Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; } | |
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureLogging(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Logging.ILoggingBuilder> configureLogging) { throw null; } |
ConfigureHostOptions could have another overload as well with the following signature:
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostOptions> configureDelegate) { throw null; } | |
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostBuilderContext, Microsoft.Extensions.Hosting.HostOptions> configureOptions) { throw null; } | |
public static Microsoft.Extensions.Hosting.IHostBuilder ConfigureHostOptions(this Microsoft.Extensions.Hosting.IHostBuilder hostBuilder, System.Action<Microsoft.Extensions.Hosting.HostOptions> configureOptions) { throw null; } |
@I-SER-I - Thanks for your help here. Are you interested in progressing this PR? If not, we can get someone else to take it forward. |
@eerhardt Sorry for the delay). I'll do it this week |
Hey @I-SER-I - I think we should fix the merge conflicts in this PR, and update it with a few suggestions. Similar to what was done #51410. What do you say? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's add the unit tests from https://github.com/dotnet/runtime/pull/51410/files#diff-030ac8a3306b8411705fab0423f5bbd96e0e7efa34ee6671db747c8d6cd8a27e here
/// <summary> | ||
/// Adds a delegate for configuring the host settings. This can be called multiple times and | ||
/// the results will be additive. | ||
/// </summary> | ||
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param> | ||
/// <param name="configureDelegate">The delegate for the <see cref="HostOptions"/>.</param> | ||
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns> | ||
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureDelegate) | ||
{ | ||
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/// <summary> | |
/// Adds a delegate for configuring the host settings. This can be called multiple times and | |
/// the results will be additive. | |
/// </summary> | |
/// <param name="hostBuilder">The <see cref="IHostBuilder"/> to configure.</param> | |
/// <param name="configureDelegate">The delegate for the <see cref="HostOptions"/>.</param> | |
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns> | |
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureDelegate) | |
{ | |
return hostBuilder.ConfigureServices((context, collection) => collection.Configure(configureDelegate)); | |
} | |
/// <summary> | |
/// Adds a delegate for configuring the <see cref="HostOptions"/> of the <see cref="IHost"/>. | |
/// </summary> | |
/// <param name="hostBuilder">The <see cref="IHostBuilder" /> to configure.</param> | |
/// <param name="configureOptions">The delegate for configuring the <see cref="HostOptions"/>.</param> | |
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns> | |
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostBuilderContext, HostOptions> configureOptions) | |
{ | |
return hostBuilder.ConfigureServices( | |
(context, collection) => collection.Configure<HostOptions>(options => configureOptions(context, options))); | |
} | |
/// <summary> | |
/// Adds a delegate for configuring the <see cref="HostOptions"/> of the <see cref="IHost"/> instance | |
/// related to th. | |
/// </summary> | |
/// <param name="hostBuilder">The <see cref="IHostBuilder" /> to configure.</param> | |
/// <param name="configureOptions">The delegate for configuring the <see cref="HostOptions"/>.</param> | |
/// <returns>The same instance of the <see cref="IHostBuilder"/> for chaining.</returns> | |
public static IHostBuilder ConfigureHostOptions(this IHostBuilder hostBuilder, Action<HostOptions> configureOptions) | |
{ | |
return hostBuilder.ConfigureServices(collection => collection.Configure(configureOptions)); | |
} |
close #48743